<template>
  <ChapterTreeComponent :subject-code="subjectCode" @check-node-change="setChekcNodes" />
</template>

<script lang="ts">
import { computed } from 'vue';
import ChapterTreeComponent from './chapter-tree.vue';
import store from '@/views/course/update/store';
import { useState } from '$';
import { ElMessage } from 'element-plus';

export default {
  components: { ChapterTreeComponent },
  setup() {
    let subjectCode = computed(() => store.state.courseInfo.subjectId);

    let [ checkNodes, setChekcNodes ] = useState([]);

    const save = (resolve, reject) => {
      if (checkNodes.value.length) {
        resolve(checkNodes.value)
      } else {
        reject();
        ElMessage.warning('请至少选择一个章节！');
      }
    }

    return { subjectCode, save, checkNodes, setChekcNodes }
  }
}
</script>

<style lang="scss" scoped>

</style>